/*

get from $GPRMC:
LAT (N): hhmm.m (separate after second character)
	hh		= hours
	mm.m	= minutes
LON (E): hhhmm.m (separate after third character)
	hhh		= hours
	mm.m	= minutes

Google Earth -> Decimal Degrees

*/


// conversion from Deg Min Sec
function convertDD()
{
	var deg = document.inDDMMSS.form1_dd.value;
	var min = document.inDDMMSS.form1_mm.value;
	var sec = document.inDDMMSS.form1_ss.value;

	if (deg == "" || min == "" || sec == ""){
			alert("Enter a value for DD MM or SS.");
	}

	else if (deg > 180 || deg < 0){
			alert("Enter a value less than 180 or greater than 0.");
	}
	else if (min > 60 || min < 0){
			alert("Enter a value less than 60 or greater than 0 for minutes.");
	}
	else if (sec > 60 || sec < 0){
			alert("Enter a value less than 60 or greater than 0 for seconds.");
	}

	else {

		document.inDDMMSS.form1_gpsdeg.value = deg;

		var dec_min = (min*1.0 + (sec/60.0));
		document.inDDMMSS.form1_gpsmin.value = dec_min;

		var answer1 = deg*1.0 + (dec_min/60.0);
		document.inDDMMSS.form1_dec.value=answer1;
	}
}

// conversion from Decimal Degrees
function convertDecDeg()
{
	var deg = 0;
	deg = document.inDecDeg.form2_dec.value;

	if (deg == ""){
			alert("Enter a value for decimal degrees.");
		}
		else if (deg > 180 || deg < 0){
			alert("Enter a value less than 180 for deg or greater than 0");
		}
	else {
		var gpsdeg = parseInt(deg);
		var remainder = deg - (gpsdeg * 1.0);
		var gpsmin = remainder * 60.0;

		document.inDecDeg.form2_gpsdeg.value = gpsdeg;
		document.inDecDeg.form2_gpsmin.value = gpsmin;

		document.inDecDeg.form2_dd.value = gpsdeg;
		document.inDecDeg.form2_mm.value= parseInt(gpsmin);
		var remainder2 = gpsmin - (parseInt(gpsmin)*1.0);
		document.inDecDeg.form2_ss.value = parseInt(remainder2*60.0);
	}
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

/*

get from $GPRMC:
LAT (N): hhmm.m (separate after second character)
	hh		= hours
	mm.m	= minutes
LON (E): hhhmm.m (separate after third character)
	hhh		= hours
	mm.m	= minutes

Google Earth -> Decimal Degrees

*/

// conversion from GPS coordinates
function convertGps()
{
	var deg = 0;
	var min = 0;
	deg = document.inGPScoord.form3_gpsdeg.value;
	min = document.inGPScoord.form3_gpsmin.value;

	if (deg == "" || min == ""){
			alert("Enter a value for GPS degrees or GPS min.");
	}
	else if (deg > 180 || deg < 0){
			alert("Degrees should be greater than 0 and less than 180.");
	}
	else if (min > 60 || min < 0){
				alert("Minutes should be greater than 0 and less than 60.");
	}
	else {

		document.inGPScoord.form3_dec.value = (deg*1.0) + min/60.0;

		document.inGPScoord.form3_dd.value = deg;
		document.inGPScoord.form3_mm.value= parseInt(min);
		var remainder2 = min - (parseInt(min)*1.0);
		document.inGPScoord.form3_ss.value = parseInt(remainder2*60.0);
	}
}
